package com.bmslz.monitor.base.factory;

import com.bmslz.monitor.service.AlarmNotify;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 告警通知工厂
 */
@Service
public class AlarmNotifyFactory {

    private final List<AlarmNotify> strategies;

    @Autowired
    public AlarmNotifyFactory(List<AlarmNotify> strategies) {
        this.strategies = strategies;
    }

    /**
     * 根据通知类型获取对应实现
     * @param notifyType 通知类型 通知类型 1 阿里云短信 2.邮箱 3.钉钉 4.公众号 5.http
     * @return
     */
    public AlarmNotify getStrategy(String notifyType) {
        return strategies.stream()
                .filter(s -> s.supports(notifyType))
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException("Unsupported data type: " + notifyType));
    }
}
